package collection;

import org.omg.CosNaming.IstringHelper;

import java.util.*;

public class ListDemo {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        // List<String> list=new LinkedList<>();

        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");

        String e=list.get(3);//list继承collection接口，多了通过下标找数据功能
        System.out.println(e);
        System.out.println(list);

        for (int i=0;i<list.size();i++){
            e=list.get(i);
            System.out.println(e);
        }
        Iterator<String> it=list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        for (String s:list) {
            System.out.println(s);
        }

        String old=list.set(2,"six");//返回值为被替换元素
        System.out.println(list);
        System.out.println(old);

//        Collections.reverse(list);//反转集合，collections是集合的工具类
        for (int i=0;i<list.size()/2;i++){
//            String str=list.get(i);
//            str=list.set(list.size()-1-i,str);
//            list.set(i,str);
            list.set(i,list.set((list.size()-1-i),list.get(i)));
        }
        System.out.println(list);
    }
}
